package it.koutifaris.travianmap.ui;

import it.koutifaris.travianmap.model.Tribe;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;

public class ImageFactory {
	private static Bitmap village[] = new Bitmap[Tribe.values().length];
	private final Resources resources;
	private final TribeResourceMapper mapper;

	public ImageFactory(Resources resources) {
		this.resources = resources;
		this.mapper = new TribeResourceMapper();
	}

	public Bitmap getVillageFor(Tribe tribe) {
		if (village[tribe.ordinal()] == null) {
			village[tribe.ordinal()] = getVillageImage(resources, tribe);
		}

		return village[tribe.ordinal()];
	}

	private Bitmap getVillageImage(Resources res, Tribe tribe) {
		return BitmapFactory.decodeResource(resources, mapper.getResourceFor(tribe));
	}

}
